/**
 * Created by karl on 2017/1/19.
 */

jQuery(document).ready(function($) {

    // 监控换面切换
    $('#js-main-slider').pogoSlider({
        autoplay: true,
        autoplayTimeout: 5000,
        displayProgess: true,
        preserveTargetSize: true,
        targetWidth: 1000,
        targetHeight: 300,
        responsive: true
    }).data('plugin_pogoSlider');

    var transitionDemoOpts = {
        displayProgess: false,
        generateNav: false,
        generateButtons: false
    }

    $('#demo1').pogoSlider(transitionDemoOpts);
    $('#demo2').pogoSlider(transitionDemoOpts);
    $('#demo3').pogoSlider(transitionDemoOpts);
    $('#demo4').pogoSlider(transitionDemoOpts);
    $('#demo5').pogoSlider(transitionDemoOpts);
    $('#demo6').pogoSlider(transitionDemoOpts);
    $('#demo7').pogoSlider(transitionDemoOpts);
    $('#demo8').pogoSlider(transitionDemoOpts);
    $('#demo9').pogoSlider(transitionDemoOpts);
    $('#demo10').pogoSlider(transitionDemoOpts);
    $('#demo11').pogoSlider(transitionDemoOpts);
    $('#demo12').pogoSlider(transitionDemoOpts);


    // 违规信息 无缝向上滚动
    var doscroll = function(){
        var $parent = $('.js-slide-list');
        var $first = $parent.find('li:first');
        var height = $first.height();
        $first.animate({
            marginTop: -height + 'px'
        }, 500, function() {
            $first.css('marginTop', 0).appendTo($parent);
        });
    };
    setInterval(function(){doscroll()}, 5000);

    // 电子地图
    window.onload = function () {
        var R = Raphael("map", 600, 500);
        //调用绘制地图方法
        paintMap(R);

        var textAttr = {
            "fill": "#fff",
            "font-size": "12px",
            "cursor": "pointer"
        };
        for (var state in china) {
            china[state]['path'].color = Raphael.getColor(0.9);
            (function (st, state) {
                //获取当前图形的中心坐标
                var xx = st.getBBox().x + (st.getBBox().width / 2);
                var yy = st.getBBox().y + (st.getBBox().height / 2);
                //***修改部分地图文字偏移坐标
                switch (china[state]['name']) {
                    case "江苏":
                        xx += 5;
                        yy -= 10;
                        break;
                    case "河北":
                        xx -= 10;
                        yy += 20;
                        break;
                    case "天津":
                        xx += 10;
                        yy += 10;
                        break;
                    case "上海":
                        xx += 10;
                        break;
                    case "广东":
                        yy -= 10;
                        break;
                    case "澳门":
                        yy += 10;
                        break;
                    case "香港":
                        xx += 20;
                        yy += 5;
                        break;
                    case "甘肃":
                        xx -= 40;
                        yy -= 30;
                        break;
                    case "陕西":
                        xx += 5;
                        yy += 10;
                        break;
                    case "内蒙古":
                        xx -= 15;
                        yy += 65;
                        break;
                    default:
                }
                //写入文字
                china[state]['text'] = R.text(xx, yy, china[state]['name']).attr(textAttr);
                st[0].onmouseover = function () {
                    st.animate({fill: st.color, stroke: "#337fcc"}, 500);
                    china[state]['text'].toFront();
                    R.safari();
                };
                st[0].onmouseout = function () {
                    st.animate({fill: "transparent", stroke: "#337fcc"}, 500);
                    china[state]['text'].toFront();
                    R.safari();
                };
            })(china[state]['path'], state);
        }
    }
});